<script setup>
import store from "@/store.js";
import Header from "@/components/Header.vue";

import {onBeforeUpdate, onMounted, onUpdated, ref, watch} from "vue";
import {useRoute, useRouter} from "vue-router";
const tokenStorage = () => {
  let token = localStorage.getItem("token")
  if (token !== null) {
    store.methods.login(token)
  }
}

const router = useRouter()

const e = ref(router.hasRoute(-1))


router.beforeEach((to, from, next) => {
  const isAuthenticated = store.state.isLogin
  if (!isAuthenticated && !['/login', '/registration'].includes(to.path)) {
    next('/login')
  } else {
    next()
  }
});

tokenStorage()
</script>

<template>
  <Header></Header>
  <router-view/>
</template>

<style scoped>
</style>
